<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>随访档案记录</title>
  <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../../lib/layui-v2.6.3/layui.js">
  <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
  </script>
  <!-- <link rel="stylesheet" href="../../css/public.css" media="all"> -->
</head>
<style>
  .layui-form-label {
    width: 150px !important;
    text-align: center !important;
  }

  .layui-input-block {
    margin-left: 150px !important;
  }
</style>

<body>
  <div class="layuimini-container">
    <div class="layuimini-main">

      <!-- <fieldset class="table-search-fieldset"> -->
      <div style="margin: 10px 10px 10px 10px">
        <div class="layui-form layui-form-pane" action="" lay-filter="followinfo">
          <div class="layui-form-item">
            <fieldset class="layui-elem-field layui-field-title">
              <legend><a class="layui-form-mid layui-word-aux" style="font-size: 15px;" name="color-design">过往随访记录</a>
              </legend>
            </fieldset>
          </div>
          <div style="margin: 10px 10px 10px 10px">
            <ul class="layui-timeline" id="followlist">
            </ul>
          </div>
        </div>
      </div>  
      <!-- </fieldset> -->
    </div>
  </div>
</body>
<script>
  //获取要显示的data
  var data_origin_follow
  function setDataFollow(data, privilege) {
    var mrId=data.id
    data_origin_follow = data

    $.ajax({
        // url: "/api/frlist.json" ,
        url: `${url_basic}/followRecord/followlist`,
        data:JSON.stringify({"mrId":data.id}),    //向后端传递档案的id
        method:'post',
        contentType:'application/json',
        success:function (data) {

          var followlist=data.data
          var html=''
          html+='<li class="layui-timeline-item"' + '>'
          html+='<i class="layui-icon layui-timeline-axis" onclick="toaddfollow(this)" value='+mrId+'>&#xe63f;</i>'
          html+='<h2 class="layui-timeline-title" '+
            'onclick="tofollowdetail(this)">'+"<pre>    "+ "添加新的随访记录..."+"</pre>"+'</h2>'+'<br>'

          
          for(var i=0;i<followlist.length;i++ ){
            var type_in = '常规随访'
            if(followlist[i].type == 1){
              type_in = "不适随访"
            }
            var batteryState_in = "正常"
            if(followlist[i].batteryState == 1){
              batteryState_in = "异常"
            }

            html+='<li class="layui-timeline-item"' + '>'
            if(followlist[i].state==1){
              html+='<i class="layui-icon layui-timeline-axis" onclick="tofollowdetail(this)" value='+followlist[i].id+'>&#xe63f;</i>'
            }else{
              html+='<i class="layui-icon layui-timeline-axis" onclick="toLabeldetail(this)" value='+followlist[i].frCount+'>&#xe63f;</i>'
            }
            html+='<h2 class="layui-timeline-title"><pre>    '+ (new  Date(followlist[i].date)).format("yyyy-MM-dd hh:mm:ss")+'</pre>'+'</h2>'
            html+='<h3><pre>      所属随访次数：'+followlist[i].frCount+'</pre></h3>'
            html+='<p><pre>   '      +'</pre></p>'
            if(followlist[i].state==1){
              html+='<h3><pre>      主治医师：'+followlist[i].doctorName+'</pre></h3>'
              html+='<p><pre>   '      +'</pre></p>'
              html+='<h3><pre>      随访种类：'+type_in+'</pre></h3>'
              html+='<p><pre>   '      +'</pre></p>'
              html+='<h3><pre>      电池状态：'+batteryState_in+'</pre></h3>'
              html+='<p><pre>   '      +'</pre></p>'
            }
            if(followlist[i].state==1){
              html+='<h3><pre>      随访状态：<span style="color:red;"class="layui-badge layui-bg-green">已完成</span></pre></h3>'
            }
            if(followlist[i].state==2){
              html+='<h3><pre>      随访状态：<span class="layui-badge">待审核</span></pre></h3>'
            }
            if(followlist[i].state==3){
              html+='<h3><pre>      随访状态：<span class="layui-badge layui-bg-orange">待修改</span></pre></h3>'
            }
            html+='<p><pre>   '+'</pre></p>'
            html+='</div>'+'</li>'
            }
          document.getElementById('followlist').innerHTML=html
        }
      });
      data_origin = data
      this_privilege = privilege
  }

  //点击按钮跳转到随访记录详情（这是一个弹窗） 
  function tofollowdetail(e){
    var frId=$(e).attr("value")
    area1 = document.body.offsetWidth < 800 ? '100%' : '800px'
    layer.open({
      type: 2,
      title: '随访记录详情',
      shadeClose: true,
      shade: 0.2,
      maxmin: true, //开启最大化最小化按钮
      area: [area1, '97%'],
      offset:10 ,
      //area: ['800px', '600px'],
      content: 'follow_detail_fromlist.html',
      success: function (layero, index) {
        var body = layer.getChildFrame('body', index ,0);
        var iframeWin = window[layero.find('iframe')[0]['name']] // //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
        $.ajax({
          url: `${url_basic}/followRecord/getOne` ,
          data:JSON.stringify({"frId":frId}),
          method:'post',
          contentType:'application/json',
          success:function(data){
            iframeWin.setDataFollow(data)
          },      
          error:function(){请求失败时执行}
        })
      },
    });
  }

  function toLabeldetail(e){
    var frCount=$(e).attr("value")
    layer.msg("暂无数据，可前往该病人的第 "+frCount+" 次随访记录的标注页面进行标注。")
  }

  function toaddfollow(e){
    var mrId=$(e).attr("value")
    area1 = document.body.offsetWidth < 800 ? '100%' : '800px'
    layer.open({
      type: 2,
      title: '添加随访记录',
      shadeClose: true,
      shade: 0.2,
      maxmin: true, //开启最大化最小化按钮
      area: [area1, '97%'],
      offset: 10,
      //area: ['800px', '600px'],
      content: 'follow_detail.html',
      success: function (layero, index) {
        var body = layer.getChildFrame('body', index ,0);
        var iframeWin = window[layero.find('iframe')[0]['name']] // //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
        iframeWin.setDataFollow(data_origin_follow)
      },
    });
  }

  
</script>
</html>